<%@ page import="driver.service.UserService_a" %>
<%@ page import="driver.service.UserServiceImpl_a" %>
<%@ page import="driver.entity.User" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.List" %><%--
  Created by IntelliJ IDEA.
  User: LSK
  Date: 2019/10/16
  Time: 16:30
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>

<head>
    <title>西安学车管家</title>
    <link rel="shortcut icon" href="img/bitbug_favicon.ico">
    <base target="_blank" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="bootstrap/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="layui/layui/css/layui.css">
    <title>用户基本汇总信息</title>
</head>

<style>
    body {
        margin: 0;
        padding: 0;
        background-color: rgb(241, 241, 241);
    }

    #search {
        background: #ffffff;
        box-shadow: 2px 0px 15px 1px rgb(231, 231, 231);
    }

    #search li {
        border-bottom: 1px solid rgb(255, 255, 255);
    }

    #search li:hover {
        border-bottom: 1px solid #5FB878;
    }

    #search .navbar-brand:hover,
    #search li a:hover {
        color: #5FB878;
    }

    .container,
    .container-fluid {
        background: #fff;
    }

    table td,
    th,
    tr {
        text-align: center;
        font-size: 13px;
    }

    #tableDelete,
    #uplook {
        font-size: 14px;
        cursor: pointer;
        border-bottom: 1px solid #555555;
    }

    #tableDelete:hover {
        color: red;
    }

    #uplook:hover {
        color: #5FB878;
    }

    .layui-layer-setwin {
        display: none;
    }

    .modal-content{
        background: rgba(255, 255, 255,0.9);
        color: rgb(0,0,0);
    }
</style>

<body>
<!--导航条-->
<nav class="navbar navbar-default " id="search">
    <div class="container">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
                    data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a target='_blank' class="aLink"  class="navbar-brand" href="index.jsp" data-toggle="tooltip" data-placement="bottom" title="返 回 首 页">
                <img src="asset/logoBig.png" style="width: 100px;height:38px;margin-top: -7px" alt="">
            </a>
        </div>

        <!-- Collect the nav links, forms, and other content for toggling -->
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <ul class="nav navbar-nav">
                <li><a target='_blank' class="aLink"  href="showusers.jsp?page=0">查看所有学员基本信息 <span class="sr-only"></span></a></li>
                <li><a target='_blank' class="aLink"  href="adduser.jsp">批量导入学员基本信息</a></li>
                <li><a target='_blank' class="aLink"  href="payfor.jsp?page=0">处理学员理赔信息</a></li>
                <li><a target='_blank' class="aLink"  href="showschools.jsp?page=0">驾校信息查看</a></li>
            </ul>
            <ul class="nav navbar-nav navbar-right">

            </ul>
        </div><!-- /.navbar-collapse -->
    </div><!-- /.container-fluid -->
</nav>
<!-- 内容主体 -->
<div class="container-fluid">
    <div>
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
            <legend>
                <!--<h2>保单信息展示</h2>-->
                <h2 >学员列表</h2>
            </legend>
        </fieldset>
        <div style="margin: 20px auto 20px;width: 90%;text-align: center">
            <div class="form-group" style="margin: 0 auto;width: 90%;float: left">
                <label for="search1" style="width: 60%"><input id="search1" type="text"
                                                               class="form-control col-lg-8" placeholder="在此输入学员姓名/手机号/身份证号码 不支持模糊查询，需要精确输入"> </label>
            </div>
            <!-- 按钮触发模态框 -->
            <button id="btn" style="width:100px;margin-left: -36%" class="btn btn-primary " data-toggle="modal"
                    data-target="#myModal">搜索</button>
            <button id="btn1" type="button" class="btn btn-primary" data-toggle="modal"
                    data-target=".bs-example-modal-lg" style="display: none"></button>
        </div>
    </div>

    <!-- 模态框（Modal） -->
    <div class="modal fade bs-example-modal-lg" data-target="#myModal" tabindex="-1" role="dialog"
         aria-labelledby="myLargeModalLabel">
        <div class="modal-dialog modal-lg" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title" id="myModalLabel">查询结果</h4>
                </div>
                <div id="div1" class="modal-body"></div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                </div>
            </div>
        </div>
    </div>


    <!--
<form class="form-inline">
    <div class="form-group">
        <label class="sr-only" for="exampleInput1"></label>
        学员姓名：<input type="text" class="form-control" id="exampleInput1" placeholder="学院姓名">
    </div>
    <div class="form-group">
        <label class="sr-only" for="exampleInput2"></label>
        学员身份证号码：<input type="text" class="form-control" id="exampleInput2" placeholder="学院姓名">
    </div>
    <div class="form-group">
        <label class="sr-only" for="exampleInput3"></label>
        学员姓名：<input type="text" class="form-control" id="exampleInput3" placeholder="学院姓名">
    </div>
    <div class="form-group">
        <label class="sr-only" for="exampleInput4"></label>
        学员身份证号码：<input type="text" class="form-control" id="exampleInput4" placeholder="学院姓名">
    </div>

    <button type="submit" class="btn btn-default">查找</button>
</form>
-->


    <table class="table table-bordered table-hover">
        <tr>
            <th>学员姓名</th>
            <th>手机号码</th>
            <th>身份证号码</th>
            <th>驾校名称</th>
            <th>保单号(个人凭证)</th>
            <th>保险类型</th>
            <th>投保阶段</th>
            <th>保险金额</th>
            <th>生效日期</th>
            <th>失效日期</th>
            <th>删除该学员</th>
            <th>查看该学员理赔记录</th>
        </tr>
        <%
            int pages=0;
            String p=request.getParameter("page");
            if(p.equals("")||p.equals("null"))
            {
                pages=0;
            }
            else
            {
                pages=Integer.valueOf(p);
            }
            System.out.println(pages);





            UserService_a service=new UserServiceImpl_a();
            ArrayList<User> users =service.selectAlluser();

            int sum=users.size();
            List<User> users2;
            if(sum<20*(pages+1))
                users2= users.subList(20*pages,sum);
            else
                users2= users.subList(20*pages,20*(pages+1));



            for(User user:users2)
            {
                out.print("<tr>");
                out.print("<td>"+user.getName()+"</td>");
                out.print("<td>"+user.getPhonenum()+"</td>");
                out.print("<td>"+user.getIdcardnum()+"</td>");
                out.print("<td>"+user.getSchool_name()+"</td>");
        %>
        <!--out.print("<td>"+user.getPolicyid()+"</td>");-->
        <td><a  target='_self' class="aHref1" style="color: #009688"  href="javascript:" lsk="<%=user.getId()%>"><%=user.getPolicyid()%></a></td>
        <!--隐藏a标签，下载专用-->
       <a target="_self" class="aHref2" style="display: none" href="javascript:" download="<%out.print(user.getName()+user.getPolicyid());%>.pdf"></a>

        <%
            out.print("<td>"+user.getPolicytype()+"</td>");
            out.print("<td>"+user.getPolicyprod()+"</td>");
            out.print("<td>"+user.getPolicynum()+"</td>");
            out.print("<td>"+user.getStarttime()+"</td>");
            out.print("<td>"+user.getEndtime()+"</td>");
            //此处用js操作吧

            //out.print("<td><a target='_blank' class="aLink"  href=\""+"user.jsp?user="+user.getId()+"\">查看</a></td>");
            //out.print("</tr>");%>
        <td><span id="tableDelete" style="color: #009688"  href="javascript:;" onclick="tableDelete(<%=user.getId()%>)">删除</span></td>
        <td><a target='_blank' class="aLink"  id="uplook"  style="color: #009688" href="applyuser.jsp?num=<%=user.getPhonenum()%>">查看</a></td>

        <%
            }
        %>

    </table>
    </span>
</div>

<nav aria-label="Page navigation">
    <ul class="pagination">
        <!--<li>
            <a target='_blank' class="aLink"  href="#" aria-label="Previous">
                <span aria-hidden="true"></span>
            </a>
        </li>-->
        <!--<li><a target='_blank' class="aLink"  href="#">1</a></li>
    <li><a target='_blank' class="aLink"  href="#">2</a></li>
    <li><a target='_blank' class="aLink"  href="#">3</a></li>
    <li><a target='_blank' class="aLink"  href="#">4</a></li>
    <li><a target='_blank' class="aLink"  href="#">5</a></li>
    <li><a target='_blank' class="aLink"  href="#">6</a></li>
    <li><a target='_blank' class="aLink"  href="#">7</a></li>
    <li><a target='_blank' class="aLink"  href="#">8</a></li>
    <li><a target='_blank' class="aLink"  href="#">9</a></li>
    <li><a target='_blank' class="aLink"  href="#">10</a></li>-->
        <%
            int n=(sum/20)+1;
            for (int i = 0; i < n; i++) {
                out.print("<li><a target='_blank'  href=\""+"showusers.jsp?page="+i+"\">"+(i+1)+""+"</a></li>");
                //out.print("<li><a target='_blank' class='aLink'   href=\"showusers.jsp?page="+i+"\">"+(i+1)+""+"</ a></li>");
            }


        %>
        <li>

        </li>
    </ul>
</nav>
</div>
<script src="bootstrap/dist/js/jquery-3.4.1.min.js"></script>
<script src="bootstrap/dist/js/bootstrap.min.js"></script>
<script src="bootstrap/dist/js/layui/layui.all.js"></script>
<script>
    layui.use('layer', function () { //独立版的layer无需执行这一句
        var $ = layui.jquery,
            layer = layui.layer; //独立版的layer无需执行这一句

        //触发事件
        var active = {
            confirmTrans: function () {
                //配置一个透明的询问框
                layer.msg('大部分参数都是可以公用的<br>合理搭配，展示不一样的风格', {
                    time: 600000, //20s后自动关闭
                });
            }
        };

        // $('#layerDemo .layui-btn').on('click', function () {
        //     var othis = $(this),
        //         method = othis.data('method');
        //     active[method] ? active[method].call(this, othis) : '';
        // });

    });
</script>
<script>
    $("#btn").click(function () {
        fun1();
        console.log("向fun1()提交数据");
    });

    function fun1() {
        console.log("你点击我了");
        $.ajax({
            url: "${pageContext.request.contextPath}/search", // 请求路径
            type: "POST", //请求方式
            //data: "username=jack&age=23",//请求参数
            data: {
                "obj": $("#search1").val(),
                "school_id": "",
            },
            // <div class="layui-layer layui-layer-dialog layui-layer-border layui-layer-msg layui-layer-hui" id="layui-layer27" type="dialog" times="27" showtime="20000" contype="string" style="z-index: 19891041; top: 301px; left: 290px;"><div id="" class="layui-layer-content">大部分参数都是可以公用的<br>合理搭配，展示不一样的风格</div><span class="layui-layer-setwin"></span><div class="layui-layer-btn layui-layer-btn-"><a target='_blank' class="aLink"  class="layui-layer-btn0">明白了</a><a target='_blank' class="aLink"  class="layui-layer-btn1">知道了</a><a target='_blank' class="aLink"  class="layui-layer-btn2">哦</a></div></div>'
            success: function (data) {
                //alert(data);
                console.log(data);
                $("#btn1").click();
                $("#div1").html(data);
            }, //响应成功后的回调函数
            error: function () {
                layer.msg(
                    '<div class="" id="layui-layer27" type="dialog" times="60" showtime="600000" contype="string" style="z-index: 19891041; top: 301px; left: 290px;"><div id="" class="layui-layer-content">搜索错误，输入框不能为空</div><span class="layui-layer-setwin"></span><div class="layui-layer-btn layui-layer-btn-"><a  class="layui-layer-btn0">知道了</a></div></div>'
                );
            }, //表示如果请求响应出现错误，会执行的回调函数
            dataType: "html" //设置接受到的响应数据的格式
        });

    }

    //点击删除后显示是否删除模态框
    function tableDelete(uid) {
        result = (function () {
            layer.confirm('确定要删除该行信息吗？', {
                icon: 3,
                title: '来自学车管家的提示'
            }, function (index) {
                //do something
                layer.close(index);
                if (index) {
                    //如果点击确定删除按钮，就会打开新窗口，否则什么都不做
                    window.open(
                        "${pageContext.request.contextPath}/deleteUser?id=" + uid )
                }
            });
        })()
    }
</script>

<script>
    /* 鼠标特效 */
    var a_idx = 0;
    jQuery(document).ready(function ($) {
        $("body").click(function (e) {
            var a = ["富强", "民主", "文明", "和谐", "自由", "平等", "公正", "法治", "爱国", "敬业", "诚信", "友善"];
            var $i = $("<span/>").text(a[a_idx]);
            a_idx = (a_idx + 1) % a.length;
            var x = e.pageX,
                y = e.pageY;
            $i.css({
                "z-index": 9999999999999999999999999999999999999999,
                "top": y - 20,
                "left": x,
                "position": "absolute",
                "font-weight": "bold",
                "color": "#ff6651"
            });
            $("body").append($i);
            $i.animate({
                    "top": y - 180,
                    "opacity": 0
                },
                1500,
                function () {
                    $i.remove();
                });
        });
    });
    //alert("用户名不存在，请联系管理员");
</script>
<script>
    var href1 = document.getElementsByClassName("aHref1");
    var href2=document.getElementsByClassName("aHref2");
    console.log(href1.length);
    for(let i=0;i<href1.length;i++)
    {
        href1[i].onclick=function () {
            console.log(href1[i].getAttribute("lsk"));
            $.ajax({
                url: "${pageContext.request.contextPath}/pdf",
                type: "POST",
                data: {
                    "uid": href1[i].getAttribute("lsk")

                },
                success: function (data) {
                    console.log(i);
                    href2[i].setAttribute("href",data);
                    href2[i].click();


                 }, //响应成功后的回调函数
                 error: function () {
                     console.log("生成PDF错误，请联系管理员");
                     alert("生成PDF错误，请联系管理员");
                 }, //表示如果请求响应出现错误，会执行的回调函数
                 dataType: "text" //设置接受到的响应数据的格式
             });







         };
     }


     /*aLink = document.getElementsByClassName("aLink"); //获取具有aLink类名的a标签，返回值是多个，组成一个数组
     aLink1 = document.getElementById("aLink1"); //获取具有aLink1的id名的a标签，返回值只有一个
     for(var i=0;i<aLink.length;i++) {
         aLink[i].onclick=function () {
             for(var i=0;i<aLink.length;i++){
                 if(aLink[i]===this){
                               console.log("测试第"+i+"个a链接情况");
                 }
             }
         }
     };*/
       /* aLink[i].onclick=function () {
            //点击了
            //执行ajax
            $.ajax({
                url: "/pdf",
                type: "POST",
                data: {
                    "uid": value,

                },
                success: function (data) {

                    //aHref.setAttribute("href",data);
                    //window.open(data);
                    /*aLink1[i].download=i+"测试.pdf";
                    aLink1[i].setAttribute("href",data);
                    aLink1[i].click();*/
                    //location.replace(data);


                    //alert(data);

                    //window.open(data);
                    //window.location.href(data);

                    //阻断
   /* }

                }, //响应成功后的回调函数
                error: function () {
                    console.log("生成PDF错误，请联系管理员");
                    alert("生成PDF错误，请联系管理员");
                }, //表示如果请求响应出现错误，会执行的回调函数
                dataType: "text" //设置接受到的响应数据的格式
            });

        }
    }*/


    /*var aHref=document.getElementById("aHref");
    var aHref2=document.getElementById("aHref2");

    aHref.onclick=function(){
        //2019-11-27逻辑 先判断是否为原始的href值，如果是则ajax，否则则不执行
        //e.preventDefault();
        //console.log("我执行了");
        var value=aHref.getAttribute("lsk");
        console.log(value);
        //console.log("/pdf"+value);
        //ajax*/







        //aHref.setAttribute("href","/pdf"+value);
        //根据ajax获取值
        //aHref.setAttribute("href","/pdf"+value);
        //aHref.click();



</script>
</body>

</html>